<template>
  <div class="app-container">
    <!--通知详情搜索部分-->
    <!--    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">-->
    <!--      <el-form-item label="学校名称" prop="schoolName">-->
    <!--        <el-input-->
    <!--          v-model="queryParams.schoolName"-->
    <!--          placeholder="请输入学校名称"-->
    <!--          clearable-->
    <!--          size="small"-->
    <!--          @keyup.enter.native="handleQuery"-->
    <!--        />-->
    <!--      </el-form-item>-->
    <!--      <el-form-item label="状态" prop="readStatus">-->
    <!--        <el-select v-model="queryParams.readStatus" placeholder="请选择状态" clearable size="small">-->
    <!--          <el-option-->
    <!--            v-for="dict in readStatusOptions"-->
    <!--            :key="dict.dictValue"-->
    <!--            :label="dict.dictLabel"-->
    <!--            :value="dict.dictValue"-->
    <!--          />-->
    <!--        </el-select>-->
    <!--      </el-form-item>-->

    <!--      <el-form-item>-->
    <!--        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
    <!--        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
    <!--      </el-form-item>-->
    <!--    </el-form>-->

    <el-button type="primary" size="mini" style="width: 60px;margin-bottom: 10px" @click="closePage">返回</el-button>
    <div style="display: flex;align-items: center;">
      <div>
        <span style="font-size: 14px;font-weight: 400;color: #666666;">通知名称：</span>
        <span style="color: #333333FF;font-size: 14px;font-weight: 400;">{{
            notifyData.title
          }}</span>
      </div>
      <div style="margin-left: 120px">
        <span style="font-size: 14px;font-weight: 400;color: #666666;">发布日期：</span>
        <span style="color: #333333FF;font-size: 14px;font-weight: 400;">{{
            notifyData.publishTime
          }}</span>
      </div>
      <!--      <div style="margin-left: 120px;display: flex;align-items: center">-->
      <!--        <span style="font-size: 14px;font-weight: 400;color: #666666;">通知内容：</span>-->
      <!--        <span style="color: #333333FF;font-size: 14px;font-weight: 400;"-->
      <!--              v-html="notifyData.content">-->
      <!--          </span>-->
      <!--      </div>-->
      <div v-if="notifyData.fileUrl"
           style="background-color: #E8F3FE;color: #1E8BFC;font-weight: 400;padding: 5px 15px;
           border-radius: 4px;font-size: 14px;width: 60px;margin-left: 6px;cursor: pointer"
           @click="handleDownload"
      >
        附件
      </div>
    </div>
    <p></p>
    <el-table v-loading="loading" :data="notifination_userList" style="color: #333333"
              :header-cell-style="{background:'#E3E3E3'}">
      <el-table-column label="日期" prop="publishTime" align="center">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.publishTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="负责人" align="center" prop="nickName"/>

      <el-table-column label="学校名称" align="center" prop="schoolName"/>
      <el-table-column label="状态" align="center">
        <template slot-scope="scope">
          <div style="display: flex;align-items: center;justify-content: center">
            <div :class="sure(scope.row.readStatus)">
            </div>
            <span>{{ statusName }}</span>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button align="center"
                     v-if="scope.row.readStatus==2"
                     size="mini"
                     type="text"
                     @click="handleLookOver(scope.row)"
          >查看回复内容
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import {
  listNotifination_user_by_notify_id,
} from "@/api/patrol/notifination_user";
import {getNotification} from "@/api/patrol/notification";

export default {

  name: "Notifination_user",
  statusName: '未读',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 通知用户表格数据
      notifination_userList: [],
      // 是否显示弹出层
      open: false,
      // 状态字典
      readStatusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        notificationId: null,
        schoolId: null,
        schoolName: null,
        readStatus: null,
        readTime: null,
        answerContent: null,
        answerFileUrl: null,
        answerTime: null,
      },
      //通知对象数据
      notifyData: {},
      // 表单参数
      form: {},
    };
  },
  mounted() {

  },
  created() {
    let id = JSON.parse(decodeURI(this.$route.query.id))
    getNotification(id).then(res => {
      this.notifyData = res.data
    })

    this.queryParams.notificationId = id
    this.getList();
    this.getDicts("read_status").then(response => {
      this.readStatusOptions = response.data;
    });
  },
  methods: {
    /** 查询通知用户列表 */
    getList() {
      this.loading = true;
      listNotifination_user_by_notify_id(this.queryParams).then(response => {
        this.notifination_userList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 状态字典翻译
    readStatusFormat(row, column) {
      return this.selectDictLabel(this.readStatusOptions, row.readStatus);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //查看回复内容
    handleLookOver(row) {
      this.$router.push({
        name: 'NotifyAnswerDetail',
        query: {
          notify: row
        }
      })
    },
    sure(res) {
      switch (res) {
        case '1':
          this.statusName = "已读"
          return 'readOk';
        case '2':
          this.statusName = "已回复"
          return 'answerOk';
        default:
          this.statusName = "未读"
          return 'readNo';
      }
    },
    handleDownload() {
      let name = "附件";
      let url = process.env.VUE_APP_BASE_API + this.notifyData.fileUrl;
      let suffix = url.substring(url.lastIndexOf("."), url.length);
      const a = document.createElement('a')
      a.setAttribute('download', name + suffix)
      a.setAttribute('target', '_blank')
      a.setAttribute('href', url)
      a.click()
    },
    //关闭页面
    closePage() {
      this.$store.dispatch('tagsView/delView', this.$route)
      // this.$router.go(-1);
      this.$tab.openPage("通知公告", "/system/notification");
    }
  }
}
;
</script>
<style scoped>

.readOk {
  width: 10px;
  height: 10px;
  border-radius: 100px;
  margin-right: 6px;
  background-color: #00B3A8;
}

.readNo {
  width: 10px;
  height: 10px;
  border-radius: 100px;
  margin-right: 6px;
  background-color: #DA1E1E;
}

.answerOk {
  width: 10px;
  height: 10px;
  border-radius: 100px;
  margin-right: 6px;
  background-color: #1E8BFC;
}
</style>
